home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / Shells / zsh / Source / src / zsh.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-07  |  45.4 KB  |  2,102 lines

  1. /*
  2.  *
  3.  * zsh.h - standard header file
  4.  *
  5.  * This file is part of zsh, the Z shell.
  6.  *
  7.  * This software is Copyright 1992 by Paul Falstad
  8.  *
  9.  * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  10.  * use this software as long as: there is no monetary profit gained
  11.  * specifically from the use or reproduction of this software, it is not
  12.  * sold, rented, traded or otherwise marketed, and this copyright notice is
  13.  * included prominently in any copy made.
  14.  *
  15.  * The author make no claims as to the fitness or correctness of this software
  16.  * for any use whatsoever, and it is provided as is. Any use of this software
  17.  * is at the user's own risk.
  18.  *
  19.  */
  20.  
  21. #include "config.h"
  22.  
  23. #ifdef HAS_UNISTD
  24. #include <unistd.h>
  25. #endif
  26. #ifdef _POSIX_VERSION
  27. #define POSIX 1
  28. #endif
  29.  
  30. #ifdef __NeXT__
  31. #include <bsd/libc.h>
  32. #endif
  33.  
  34. #include <stdio.h>
  35. #include <ctype.h>
  36.  
  37. #ifdef HAS_STRING
  38. #include <string.h>
  39. #else
  40. #include <strings.h>
  41. #endif
  42.  
  43. #ifdef HAS_MEMORY
  44. #include <memory.h>
  45. #endif
  46.  
  47. #ifdef HAS_LOCALE
  48. #include <locale.h>
  49. #endif
  50.  
  51. #ifdef HAS_STDLIB
  52. #include <stdlib.h>
  53. #endif
  54.  
  55. #ifdef SYSV
  56.  
  57. #ifndef SYSVR4
  58. #if defined(SCO)
  59. #include <limits.h>
  60. #include <sys/types.h>
  61. #include <sys/stat.h>
  62. #define MAXPATHLEN 255
  63. #else
  64. #include <sys/bsdtypes.h>
  65. #include <sys/limits.h>
  66. #include <sys/sioctl.h>
  67. #define MAXPATHLEN PATH_MAX
  68. #define lstat stat
  69. #endif
  70. #endif
  71.  
  72. #if defined(IRIX5) || defined(SCO)
  73. #include <sys/signal.h>
  74. #endif
  75.  
  76. int gethostname();
  77.  
  78. #else /* not SYSV */
  79.  
  80. #include <sys/types.h>        /* this is the key to the whole thing */
  81.  
  82. #endif /* not SYSV */
  83.  
  84. #ifdef _IBMR2
  85. #undef _BSD            /* union wait SUCKS! */
  86. #include <sys/wait.h>
  87. #define _BSD
  88. #else
  89. #ifdef HAS_WAIT
  90. #include <wait.h>
  91. #else
  92. #include <sys/wait.h>
  93. #endif
  94. #endif
  95.  
  96. #if defined(IRIX5) && defined(_POSIX_SOURCE)
  97. /* this stuff is in <sys/wait.h> but with _POSIX_SOURCE
  98.  * it will not be seen -- this is correct but not nice
  99.  * considering using "union wait" */
  100. typedef union wait    {
  101.     int    w_status;        /* used in syscall */
  102.     struct {
  103. #ifdef _MIPSEL
  104.         unsigned int    w_Termsig:7,    /* termination signal */
  105.                 w_Coredump:1,    /* core dump indicator */
  106.                 w_Retcode:8,    /* exit code if w_termsig==0 */
  107.                 w_Filler:16;    /* upper bits filler */
  108. #endif
  109. #ifdef _MIPSEB
  110.         unsigned int    w_Filler:16,    /* upper bits filler */
  111.                 w_Retcode:8,    /* exit code if w_termsig==0 */
  112.                 w_Coredump:1,    /* core dump indicator */
  113.                 w_Termsig:7;    /* termination signal */
  114. #endif
  115.     } w_T;
  116.     /*
  117.      * Stopped process status.  Returned
  118.      * only for traced children unless requested
  119.      * with the WUNTRACED option bit.
  120.      */
  121.     struct {
  122. #ifdef _MIPSEL
  123.         unsigned int    w_Stopval:8,    /* == W_STOPPED if stopped */
  124.                 w_Stopsig:8,    /* signal that stopped us */
  125.                 w_Filler:16;    /* upper bits filler */
  126. #endif
  127. #ifdef _MIPSEB
  128.         unsigned int    w_Filler:16,    /* upper bits filler */
  129.                 w_Stopsig:8,    /* signal that stopped us */
  130.                 w_Stopval:8;    /* == W_STOPPED if stopped */
  131. #endif
  132.     } w_S;
  133. } wait_t;
  134. #endif
  135.  
  136. #ifdef _CRAY
  137. #define MAXPATHLEN PATH_MAX
  138. #include <sys/machd.h>        /* HZ definition here */
  139. #endif
  140.  
  141. #if defined(HAS_TIME) || defined(_CRAY) || defined(IRIX5)
  142. #include <time.h>
  143. #if (defined(_CRAY) && defined(__STDC__)) || defined(IRIX5)
  144. #include <sys/time.h>
  145. #endif
  146. #else
  147. #include <sys/time.h>
  148. #endif
  149.  
  150. #if defined(IRIX5) || defined(SCO)
  151. #include <sys/select.h>    /* needs timeval */
  152. #endif
  153.  
  154. #ifdef SYSV
  155. #include <fcntl.h>
  156. #else
  157. #include <sys/file.h>
  158. #endif
  159.  
  160. #if !defined(SYSV) || defined(SYSVR4)
  161. #include <sys/resource.h>
  162. #endif
  163.  
  164. #include <signal.h>
  165. #ifdef USE_SIGSET
  166. #undef signal
  167. #define signal sigset
  168. #endif
  169.  
  170. #if defined(SCO)
  171. #include <sys/stream.h>
  172. #include <sys/ptem.h>
  173. #endif
  174.  
  175. #ifdef HAS_TERMIO
  176. #define VDISABLEVAL -1
  177. #define HAS_TIO 1
  178. #include <sys/termio.h>
  179. #else
  180. #ifdef HAS_TERMIOS
  181. #define VDISABLEVAL 0
  182. #define HAS_TIO 1
  183. #include <termios.h>
  184. #ifdef __sgi
  185. #ifndef VSWTCH
  186. #define VSWTCH 7 /* VSWTCH not defined if _POSIX_SOURCE */
  187. #endif
  188. #ifndef CSWTCH
  189. #ifndef CTRL
  190. #define    CTRL(c)    ((c)&037)
  191. #endif
  192. #define CSWTCH CTRL('z') /* CSWTCH not defined if _POSIX_SOURCE */
  193. #endif
  194. #ifndef XTABS
  195. #define XTABS 0014000 /* XTABS not defined if _POSIX_SOURCE */
  196. #endif
  197. #ifndef ONLCR
  198. #define    ONLCR 0000004 /* ONLCR not defined if _POSIX_SOURCE */
  199. #endif
  200. #endif /* __sgi */
  201. #else
  202. #include <sgtty.h>
  203. #endif
  204. #endif
  205.  
  206. #if defined(SYSV) && !defined(SYSVR4)
  207. #define readlink(s,t,z)    (-1)
  208. #undef TIOCGWINSZ
  209. #endif
  210.  
  211. #include <sys/param.h>
  212. #if defined(_CRAY) && defined(__STDC__)
  213. #define OPEN_MAX 64
  214. #define NOFILE OPEN_MAX
  215. #endif
  216.  
  217. #if defined(SCO)
  218. #define NOFILE _POSIX_OPEN_MAX
  219. #endif
  220.  
  221. #if defined(SCO)
  222. #include <utime.h>
  223. #endif
  224. #include <sys/times.h>
  225.  
  226. #ifdef HAS_DIRENT
  227. #if defined(ardent)    /* ardent = Titan */ 
  228. #include <sys/dirent.h>
  229. #endif
  230. #include <dirent.h>    
  231. #else            
  232. #include <sys/dir.h>    
  233. #endif
  234. #if defined(__NeXT__)
  235. #define dirent direct    /* if you have absolutely no struct dirent */
  236. #endif            /* anywhere in system headers, add your */
  237.             /* system here and pray */
  238.  
  239. #ifdef __hp9000s800
  240. #include <sys/bsdtty.h>
  241. #endif
  242.  
  243. #if !defined(sun) && (!defined(SYSVR4) || defined(DGUX))
  244. #if defined(_IBMR2) && defined(NOFLSH)
  245. #undef NOFLSH
  246. #endif
  247. #ifndef ardent
  248. #include <sys/ioctl.h>
  249. #endif
  250. #else
  251. #include <sys/filio.h>        /* for FIONREAD */
  252. #endif
  253.  
  254. #ifdef __STDC__
  255. #define DCLPROTO(X) X
  256. /* prototype template for static functions */
  257. /* Note that the argument list "a" must have its own ()s around it */
  258. #define SPROTO(f,a) static f a
  259. #include <fcntl.h>
  260. #include <sys/stat.h>
  261. #ifndef NULL
  262. #define NULL ((void *)0)
  263. #endif
  264. #else                /* K&R C */
  265. #define DCLPROTO(X) ()
  266. #define SPROTO(f,a) static f()
  267. /* SGI cc digs "const" even when K&R */
  268. #if !(defined(__sgi) && defined(__mips))
  269. #define const
  270. #endif
  271. #include <sys/stat.h>
  272. #ifndef NULL
  273. #define NULL 0
  274. #endif
  275. #endif
  276.  
  277. #ifdef HAS_UTMPX
  278. #include <utmpx.h>
  279. #define utmp utmpx
  280. #define ut_time ut_xtime
  281. #undef UTMP_FILE
  282. #define UTMP_FILE UTMPX_FILE
  283. #undef WTMP_FILE
  284. #define WTMP_FILE WTMPX_FILE
  285. #else
  286. #include <utmp.h>
  287. #endif
  288.  
  289. #if !defined(UTMP_FILE) && defined(_PATH_UTMP)
  290. #define UTMP_FILE _PATH_UTMP
  291. #endif
  292. #if !defined(WTMP_FILE) && defined(_PATH_WTMP)
  293. #define WTMP_FILE _PATH_WTMP
  294. #endif
  295.  
  296. #define DEFWORDCHARS "*?_-.[]~=/&;!#$%^(){}<>"
  297. #define DEFTIMEFMT "%E real  %U user  %S system  %P %J"
  298. #ifdef UTMP_HOST
  299. #define DEFWATCHFMT "%n has %a %l from %m."
  300. #else
  301. #define DEFWATCHFMT "%n has %a %l."
  302. #endif
  303.  
  304. #ifdef GLOBALS
  305. #define EXTERN
  306. #else
  307. #define EXTERN extern
  308. #endif
  309.  
  310. #ifdef HAS_STRING
  311. #define killpg(pgrp,sig) kill(-(pgrp),sig)
  312. #endif
  313.  
  314. /* SYSV or POSIX compatible BSD */
  315. /* ARGH, this is currently broken as the 'BSD' test had to be taken stripped
  316.  * of an additional test BSD >= 199301 as Solaris cpp is broken ++jhi; */
  317. #if (defined(SYSV) || defined(_POSIX_SOURCE) || defined(BSD) || defined(__convex__) || defined(_CRAY) || defined(__osf__) || defined(__linux__)) && !defined(NeXT)
  318. #if !defined(__sgi) || !defined(_BSD_COMPAT) /* IRIX */
  319. #ifdef __hpux
  320. #define GETPGRP()  getpgrp2(0)
  321. #else
  322. #define GETPGRP()  getpgrp()
  323. #endif
  324. #else
  325. #define GETPGRP()  getpgrp(0)
  326. #endif
  327. #else
  328. #define GETPGRP()  getpgrp(0)
  329. #endif
  330.  
  331. #if defined(__sgi) && defined(__STDC__) && (defined(_BSD_COMPAT) || defined(_BSD_SIGNALS))
  332. #ifdef IRIX5
  333. #define gettimeofday(tp, tzp) BSDgettimeofday(tp, tzp)
  334. #else
  335. #undef signal
  336. #define signal(s, h) BSDsignal(s, (HANDTYPE (*)()) h)
  337. #endif
  338. #endif
  339.  
  340. #ifndef F_OK
  341. #define F_OK 00
  342. #define R_OK 04
  343. #define W_OK 02
  344. #define X_OK 01
  345. #endif
  346.  
  347. /* sigvec sv_handler needs special casting */
  348. #if defined(__convexc__)
  349. #define SIGVEC_HANDTYPE _SigFunc_Ptr_t
  350. #else
  351. #if defined(IRIX5)
  352. #define SIGVEC_HANDTYPE __sigret_t (*)()
  353. #else
  354. #if defined(ultrix)
  355. /* Ultrix has void here but HANDTYPE is int? */
  356. #define SIGVEC_HANDTYPE void (*)()
  357. #else
  358. #define SIGVEC_HANDTYPE HANDTYPE (*)()
  359. #endif
  360. #endif
  361. #endif
  362.  
  363. /* math.c */
  364. typedef int LV;
  365.  
  366. #include "zle.h"
  367.  
  368. /* size of job list */
  369.  
  370. #define MAXJOB 80
  371.  
  372. /* memory allocation routines - changed with permalloc()/heapalloc() */
  373.  
  374. /* real things in mem.c */
  375. extern vptr(*alloc) DCLPROTO((int));
  376. extern vptr(*ncalloc) DCLPROTO((int));
  377.  
  378. /* character tokens */
  379.  
  380. #define ALPOP            ((char) 0x81)
  381. #define HISTSPACE        ((char) 0x83)
  382. #define Pound            ((char) 0x84)
  383. #define String            ((char) 0x85)
  384. #define Hat            ((char) 0x86)
  385. #define Star            ((char) 0x87)
  386. #define Inpar            ((char) 0x88)
  387. #define Outpar            ((char) 0x89)
  388. #define Qstring                ((char) 0x8a)
  389. #define Equals            ((char) 0x8b)
  390. #define Bar                  ((char) 0x8c)
  391. #define Inbrace                ((char) 0x8d)
  392. #define Outbrace        ((char) 0x8e)
  393. #define Inbrack                ((char) 0x8f)
  394. #define Outbrack        ((char) 0x90)
  395. #define Tick            ((char) 0x91)
  396. #define Inang            ((char) 0x92)
  397. #define Outang            ((char) 0x93)
  398. #define Quest            ((char) 0x94)
  399. #define Tilde            ((char) 0x95)
  400. #define Qtick            ((char) 0x96)
  401. #define Comma            ((char) 0x97)
  402. #define Snull            ((char) 0x98)
  403. #define Dnull            ((char) 0x99)
  404. #define Bnull            ((char) 0x9a)
  405. #define Nularg            ((char) 0x9b)
  406.  
  407. #define INULL(x)        (((x) & 0xf8) == 0x98)
  408.  
  409. /* Character tokens are sometimes casted to (unsigned char)'s. Unfortunately,
  410.    SVR4's deceiving compiler botches non-terminal, same size, signed to
  411.    unsigned promotions; i.e. (int) (unsigned char) ((char) -1) evaluates to
  412.    -1,     not 255 as it should!
  413.    We circumvent the troubles of such shameful delinquency by casting to a
  414.    larger unsigned type then back down to unsigned char.          --
  415.    Marc Boucher <marc@cam.org>
  416.    Dec Alpha OSF compilers have the same property
  417.    <daniel@ug.eds.com> 25-Jan-1993 */
  418.  
  419. #if (defined(SYSVR4) || defined (__osf__)) && !defined(__GNUC__)
  420. #define STOUC(X)    ((unsigned char)(unsigned short)(X))
  421. #else
  422. #define STOUC(X)    ((unsigned char)(X))
  423. #endif
  424.  
  425. /*
  426.  * The source was full of implicit casts between signed and unsigned
  427.  * character pointers.  To get a clean compile, I've made these casts
  428.  * explicit, but the potential for error is still there.  If your machine
  429.  * needs special treatment, just define your own macros here.
  430.  *     --jim <jmattson@ucsd.edu>
  431.  */
  432.  
  433. #define STOUCP(X)    ((unsigned char *)(X))
  434. #define UTOSCP(X)    ((char *)(X))
  435.  
  436. /* chars that need to be quoted if meant literally */
  437.  
  438. #define SPECCHARS "#$^*()$=|{}[]`<>?~;&!\n\t \\\'\""
  439.  
  440. /* ALPOP in the form of a string */
  441.  
  442. #define ALPOPS " \201"
  443. #define HISTMARK "\201"
  444.  
  445. #define SEPER 1
  446. #define NEWLIN 2
  447. #define LEXERR 3
  448. #define SEMI 4
  449. #define DSEMI 5
  450. #define AMPER 6
  451. #define INPAR 7
  452. #define INBRACE 8
  453. #define OUTPAR 9
  454. #define DBAR 10
  455. #define DAMPER 11
  456. #define BANG 12
  457. #define OUTBRACE 13
  458. #define OUTANG 14
  459. #define OUTANGBANG 15
  460. #define DOUTANG 16
  461. #define DOUTANGBANG 17
  462. #define INANG 18
  463. #define DINANG 19
  464. #define DINANGDASH 20
  465. #define INANGAMP 21
  466. #define OUTANGAMP 22
  467. #define OUTANGAMPBANG 23
  468. #define DOUTANGAMP 24
  469. #define DOUTANGAMPBANG 25
  470. #define TRINANG 26
  471. #define BAR 27
  472. #define BARAMP 28
  473. #define DINBRACK 29
  474. #define DOUTBRACK 30
  475. #define STRING 31
  476. #define ENVSTRING 32
  477. #define ENVARRAY 33
  478. #define ENDINPUT 34
  479. #define INOUTPAR 35
  480. #define DO 36
  481. #define DONE 37
  482. #define ESAC 38
  483. #define THEN 39
  484. #define ELIF 40
  485. #define ELSE 41
  486. #define FI 42
  487. #define FOR 43
  488. #define CASE 44
  489. #define IF 45
  490. #define WHILE 46
  491. #define FUNC 47
  492. #define REPEAT 48
  493. #define TIME 49
  494. #define UNTIL 50
  495. #define EXEC 51
  496. #define COMMAND 52
  497. #define SELECT 53
  498. #define COPROC 54
  499. #define NOGLOB 55
  500. #define DASH 56
  501. #define NOCORRECT 57
  502. #define FOREACH 58
  503. #define ZEND 59
  504. #define DINPAR 60
  505. #define DOUTPAR 61
  506.  
  507. #define WRITE 0
  508. #define WRITENOW 1
  509. #define APP 2
  510. #define APPNOW 3
  511. #define MERGEOUT 4
  512. #define MERGEOUTNOW 5
  513. #define ERRAPP 6
  514. #define ERRAPPNOW 7
  515. #define READ 8
  516. #define HEREDOC 9
  517. #define HEREDOCDASH 10
  518. #define HERESTR 11
  519. #define MERGE 12
  520. #define CLOSE 13
  521. #define INPIPE 14
  522. #define OUTPIPE 15
  523. #define NONE 16
  524.  
  525. #ifdef GLOBALS
  526. int redirtab[TRINANG - OUTANG + 1] =
  527. {
  528.     WRITE,
  529.     WRITENOW,
  530.     APP,
  531.     APPNOW,
  532.     READ,
  533.     HEREDOC,
  534.     HEREDOCDASH,
  535.     MERGE,
  536.     MERGEOUT,
  537.     MERGEOUTNOW,
  538.     ERRAPP,
  539.     ERRAPPNOW,
  540.     HERESTR,
  541. };
  542.  
  543. #else
  544. extern int redirtab[TRINANG - OUTANG + 1];
  545.  
  546. #endif
  547.  
  548. #ifdef GLOBALS
  549. char nulstring[] =
  550. {Nularg, '\0'};
  551. int nulstrlen = sizeof(nulstring) - 1;
  552.  
  553. #else
  554. extern char nulstring[];
  555. extern int nulstrlen;
  556.  
  557. #endif
  558.  
  559. #define IS_READFD(X) ((X)>=READ && (X)<=MERGE)
  560. #define IS_REDIROP(X) ((X)>=OUTANG && (X)<=TRINANG)
  561. #define IS_ERROR_REDIR(X) ((X)>=MERGEOUT && (X)<=ERRAPPNOW)
  562. #define UN_ERROR_REDIR(X) ((X)-MERGEOUT+WRITE)
  563.  
  564. #define FD_WORD   -1
  565. #define FD_COPROC -2
  566. #define FD_CLOSE  -3
  567.  
  568. extern char **environ;
  569.  
  570. /* linked list abstract data type */
  571.  
  572. struct lknode {
  573.     struct lknode *next, *last;
  574.     vptr dat;
  575. };
  576. struct lklist {
  577.     struct lknode *first, *last;
  578. };
  579.  
  580. typedef struct hashtab *Hashtab;
  581. typedef struct hashnode *Hashnode;
  582. typedef struct schedcmd *Schedcmd;
  583. typedef struct alias *Alias;
  584. typedef struct process *Process;
  585. typedef struct job *Job;
  586. typedef struct value *Value;
  587. typedef struct arrind *Arrind;
  588. typedef struct varasg *Varasg;
  589. typedef struct param *Param;
  590. typedef struct cmdnam *Cmdnam;
  591. typedef struct cond *Cond;
  592. typedef struct cmd *Cmd;
  593. typedef struct pline *Pline;
  594. typedef struct sublist *Sublist;
  595. typedef struct list *List;
  596. typedef struct lklist *Lklist;
  597. typedef struct lknode *Lknode;
  598. typedef struct comp *Comp;
  599. typedef struct redir *Redir;
  600. typedef struct complist *Complist;
  601. typedef struct heap *Heap;
  602. typedef struct heappos *Heappos;
  603. typedef struct histent *Histent;
  604. typedef struct compctlp *Compctlp;
  605. typedef struct compctl *Compctl;
  606. typedef struct compcond *Compcond;
  607. typedef void (*FFunc) DCLPROTO((vptr));
  608. typedef vptr(*VFunc) DCLPROTO((vptr));
  609. typedef void (*HFunc) DCLPROTO((char *, char *));
  610.  
  611. #define addnode(X,Y) insnode(X,(X)->last,Y)
  612. #define full(X) ((X)->first != NULL)
  613. #define empty(X) ((X)->first == NULL)
  614. #define firstnode(X) ((X)->first)
  615. #define getaddrdata(X) (&((X)->dat))
  616. #define getdata(X) ((X)->dat)
  617. #define setdata(X,Y) ((X)->dat = (Y))
  618. #define lastnode(X) ((X)->last)
  619. #define nextnode(X) ((X)->next)
  620. #define prevnode(X) ((X)->last)
  621. #define peekfirst(X) ((X)->first->dat)
  622. #define pushnode(X,Y) insnode(X,(Lknode) X,Y)
  623. #define incnode(X) (X = nextnode(X))
  624. #define gethistent(X) (histentarr+((X)%histentct))
  625.  
  626. /* node structure for syntax trees */
  627.  
  628. /* struct list, struct sublist, struct pline, etc.  all fit the form
  629.     of this structure and are used interchangably.
  630.     The ptrs may hold integers or pointers, depending on the type of
  631.     the node.
  632. */
  633.  
  634. struct node {
  635.     int type;            /* node type */
  636. };
  637.  
  638. #define N_LIST 0
  639. #define N_SUBLIST 1
  640. #define N_PLINE 2
  641. #define N_CMD 3
  642. #define N_REDIR 4
  643. #define N_COND 5
  644. #define N_FOR 6
  645. #define N_CASE 7
  646. #define N_IF 8
  647. #define N_WHILE 9
  648. #define N_VARASG 10
  649. #define N_COUNT 11
  650.  
  651. /* values for types[4] */
  652.  
  653. #define NT_EMPTY 0
  654. #define NT_NODE  1
  655. #define NT_STR   2
  656. #define NT_LIST  4
  657. #define NT_ARR   8
  658.  
  659. #define NT_TYPE(T) ((T) & 0xff)
  660. #define NT_N(T, N) (((T) >> (8 + (N) * 4)) & 0xf)
  661. #define NT_SET(T0, N, T1, T2, T3, T4) \
  662.     ((T0) | ((N) << 24) | \
  663.      ((T1) << 8) | ((T2) << 12) | ((T3) << 16) | ((T4) << 20))
  664. #define NT_NUM(T) (((T) >> 24) & 7)
  665. #define NT_HEAP   (1 << 30)
  666.  
  667. /* tree element for lists */
  668.  
  669. struct list {
  670.     int ntype;
  671.     int type;
  672.     Sublist left;
  673.     List right;
  674. };
  675.  
  676. #define SYNC 0            /* ; */
  677. #define ASYNC 1            /* & */
  678. #define TIMED 2
  679.  
  680. /* tree element for sublists */
  681.  
  682. struct sublist {
  683.     int ntype;
  684.     int type;
  685.     int flags;            /* see PFLAGs below */
  686.     Pline left;
  687.     Sublist right;
  688. };
  689.  
  690. #define ORNEXT 10        /* || */
  691. #define ANDNEXT 11        /* && */
  692.  
  693. #define PFLAG_NOT 1        /* ! ... */
  694. #define PFLAG_COPROC 32        /* coproc ... */
  695.  
  696. /* tree element for pipes */
  697.  
  698. struct pline {
  699.     int ntype;
  700.     int type;
  701.     Cmd left;
  702.     Pline right;
  703. };
  704.  
  705. #define END    0    /* pnode *right is null */
  706. #define PIPE    1    /* pnode *right is the rest of the pipeline */
  707.  
  708. /* tree element for commands */
  709.  
  710. struct cmd {
  711.     int ntype;
  712.     int type;
  713.     int flags;            /* see CFLAGs below */
  714.     Lklist args;        /* command & argmument List (char *'s) */
  715.     union {
  716.     List list;        /* for SUBSH/CURSH/SHFUNC */
  717.     struct forcmd *forcmd;
  718.     struct casecmd *casecmd;
  719.     struct ifcmd *ifcmd;
  720.     struct whilecmd *whilecmd;
  721.     Sublist pline;
  722.     Cond cond;
  723.     vptr generic;
  724.     } u;
  725.     Lklist redir;        /* i/o redirections (struct redir *'s) */
  726.     Lklist vars;        /* param assignments (struct varasg *'s) */
  727. };
  728.  
  729. #define SIMPLE 0
  730. #define SUBSH 1
  731. #define CURSH 2
  732. #define ZCTIME 3
  733. #define FUNCDEF 4
  734. #define CFOR 5
  735. #define CWHILE 6
  736. #define CREPEAT 7
  737. #define CIF 8
  738. #define CCASE 9
  739. #define CSELECT 10
  740. #define COND 11
  741.  
  742. #define CFLAG_EXEC 1        /* exec ... */
  743. #define CFLAG_COMMAND 2        /* command ... */
  744. #define CFLAG_NOGLOB 4        /* noglob ... */
  745. #define CFLAG_DASH 8        /* - ... */
  746.  
  747. /* tree element for redirection lists */
  748.  
  749. struct redir {
  750.     int ntype;
  751.     int type, fd1, fd2;
  752.     char *name;
  753. };
  754.  
  755. /* tree element for conditionals */
  756.  
  757. struct cond {
  758.     int ntype;
  759.     int type;            /* can be cond_type, or a single letter (-a, -b, ...) */
  760.     vptr left, right;
  761. };
  762.  
  763. #define COND_NOT 0
  764. #define COND_AND 1
  765. #define COND_OR 2
  766. #define COND_STREQ 3
  767. #define COND_STRNEQ 4
  768. #define COND_STRLT 5
  769. #define COND_STRGTR 6
  770. #define COND_NT 7
  771. #define COND_OT 8
  772. #define COND_EF 9
  773. #define COND_EQ 10
  774. #define COND_NE 11
  775. #define COND_LT 12
  776. #define COND_GT 13
  777. #define COND_LE 14
  778. #define COND_GE 15
  779.  
  780. struct forcmd {            /* for/select */
  781. /* Cmd->args contains list of words to loop thru */
  782.     int ntype;
  783.     int inflag;            /* if there is an in ... clause */
  784.     char *name;            /* parameter to assign values to */
  785.     List list;            /* list to look through for each name */
  786. };
  787. struct casecmd {
  788. /* Cmd->args contains word to test */
  789.     int ntype;
  790.     char **pats;
  791.     List *lists;        /* list to execute */
  792. };
  793.  
  794. /*
  795.  
  796.     a command like "if foo then bar elif baz then fubar else fooble"
  797.     generates a tree like:
  798.  
  799.     struct ifcmd a = { next =  &b,  ifl = "foo", thenl = "bar" }
  800.     struct ifcmd b = { next =  &c,  ifl = "baz", thenl = "fubar" }
  801.     struct ifcmd c = { next = NULL, ifl = NULL, thenl = "fooble" }
  802.  
  803. */
  804.  
  805. struct ifcmd {
  806.     int ntype;
  807.     List *ifls;
  808.     List *thenls;
  809. };
  810.  
  811. struct whilecmd {
  812.     int ntype;
  813.     int cond;            /* 0 for while, 1 for until */
  814.     List cont;            /* condition */
  815.     List loop;            /* list to execute until condition met */
  816. };
  817.  
  818. /* structure used for multiple i/o redirection */
  819. /* one for each fd open */
  820.  
  821. struct multio {
  822.     int ct;        /* # of redirections on this fd */
  823.     int rflag;        /* 0 if open for reading, 1 if open for writing */
  824.     int pipe;        /* fd of pipe if ct > 1 */
  825.     int fds[NOFILE];    /* list of src/dests redirected to/from this fd */
  826. };
  827.  
  828. /* node used in command path hash table (cmdnamtab) */
  829.  
  830. struct cmdnam {
  831.     struct hashnode *next;
  832.     char *nam;            /* hash data */
  833.     int flags;
  834.     union {
  835.     char **name;        /* full pathname if !(flags & BUILTIN) */
  836.     char *cmd;        /* file name for hashed commands */
  837.     int binnum;        /* func to exec if type & BUILTIN */
  838.     List list;        /* list to exec if type & SHFUNC */
  839.     }
  840.     u;
  841. };
  842.  
  843. #define EXCMD        0x10000
  844. #define BUILTIN      0x20000
  845. #define SHFUNC       0x40000
  846. #define DISABLED     0x80000
  847. #define HASHCMD      (EXCMD | BUILTIN)
  848.  
  849. #define ISEXCMD(X) ((X) & EXCMD)
  850.  
  851. /* node used in parameter hash table (paramtab) */
  852.  
  853. struct param {
  854.     struct hashnode *next;
  855.     char *nam;            /* hash data */
  856.     union {
  857.     char **arr;        /* value if declared array */
  858.     char *str;        /* value if declared string (scalar) */
  859.     long val;        /* value if declared integer */
  860.     }
  861.     u;
  862.     union {            /* functions to call to set value */
  863.     void (*cfn) DCLPROTO((Param, char *));
  864.     void (*ifn) DCLPROTO((Param, long));
  865.     void (*afn) DCLPROTO((Param, char **));
  866.     }
  867.     sets;
  868.     union {            /* functions to call to get value */
  869.     char *(*cfn) DCLPROTO((Param));
  870.     long (*ifn) DCLPROTO((Param));
  871.     char **(*afn) DCLPROTO((Param));
  872.     }
  873.     gets;
  874.     int ct;            /* output base or field width */
  875.     int flags;
  876.     vptr data;            /* used by getfns */
  877.     char *env;            /* location in environment, if exported */
  878.     char *ename;        /* name of corresponding environment var */
  879.     Param old;            /* old struct for use with local */
  880.     int level;            /* if (old != NULL), level of localness */
  881. };
  882.  
  883. #define PMFLAG_s 0        /* scalar */
  884. #define PMFLAG_L 1        /* left justify and remove leading blanks */
  885. #define PMFLAG_R 2        /* right justify and fill with leading blanks */
  886. #define PMFLAG_Z 4        /* right justify and fill with leading zeros */
  887. #define PMFLAG_i 8        /* integer */
  888. #define PMFLAG_l 16        /* all lower case */
  889. #define PMFLAG_u 32        /* all upper case */
  890. #define PMFLAG_r 64        /* readonly */
  891. #define PMFLAG_t 128        /* tagged */
  892. #define PMFLAG_x 256        /* exported */
  893. #define PMFLAG_A 512        /* array */
  894. #define PMFLAG_SPECIAL    1024
  895. #define PMFLAG_UNSET    2048
  896. #define PMTYPE (PMFLAG_i|PMFLAG_A)
  897. #define pmtype(X) ((X)->flags & PMTYPE)
  898.  
  899. /* variable assignment tree element */
  900.  
  901. struct varasg {
  902.     int ntype;
  903.     int type;            /* nonzero means array */
  904.     char *name;
  905.     char *str;            /* should've been a union here.  oh well */
  906.     Lklist arr;
  907. };
  908.  
  909. /* lvalue for variable assignment/expansion */
  910.  
  911. struct value {
  912.     int isarr;
  913.     struct param *pm;        /* parameter node */
  914.     int inv;            /* should we return the index ? */
  915.     int a;            /* first element of array slice, or -1 */
  916.     int b;            /* last element of array slice, or -1 */
  917. };
  918.  
  919. struct fdpair {
  920.     int fd1, fd2;
  921. };
  922.  
  923. /* tty state structure */
  924.  
  925. struct ttyinfo {
  926. #ifdef HAS_TERMIOS
  927.     struct termios tio;
  928. #else
  929. #ifdef HAS_TERMIO
  930.     struct termio tio;
  931. #else
  932.     struct sgttyb sgttyb;
  933.     int lmodes;
  934.     struct tchars tchars;
  935.     struct ltchars ltchars;
  936. #endif
  937. #endif
  938. #ifdef TIOCGWINSZ
  939.     struct winsize winsize;
  940. #endif
  941. };
  942.  
  943. /* entry in job table */
  944.  
  945. struct job {
  946.     long gleader;        /* process group leader of this job */
  947.     int stat;
  948.     char *pwd;            /* current working dir of shell when
  949.                    this job was spawned */
  950.     struct process *procs;    /* list of processes */
  951.     Lklist filelist;        /* list of files to delete when done */
  952.     int stty_in_env;        /* if STTY=... is present */
  953.     struct ttyinfo *ty;        /* the modes specified by STTY */
  954. };
  955.  
  956. #define STAT_CHANGED 1        /* status changed and not reported */
  957. #define STAT_STOPPED 2        /* all procs stopped or exited */
  958. #define STAT_TIMED 4        /* job is being timed */
  959. #define STAT_DONE 8
  960. #define STAT_LOCKED 16        /* shell is finished creating this job,    may be
  961.                    deleted from job table */ 
  962. #define STAT_INUSE 64        /* this job entry is in use */
  963.  
  964. #define SP_RUNNING -1        /* fake statusp for running jobs */
  965.  
  966. #ifndef RUSAGE_CHILDREN
  967. #undef HAS_RUSAGE
  968. #endif
  969.  
  970. struct timeinfo {
  971. #ifdef HAS_RUSAGE
  972.     struct rusage ru;
  973. #else
  974.     long ut, st;
  975. #endif
  976. };
  977.  
  978. /* node in job process lists */
  979.  
  980. #define JOBTEXTSIZE 80
  981.  
  982. struct process {
  983.     struct process *next;
  984.     long pid;
  985.     char text[JOBTEXTSIZE];    /* text to print when 'jobs' is run */
  986.     int statusp;        /* return code from wait3() */
  987.     struct timeinfo ti;
  988.     struct timeval bgtime;    /* time job was spawned */
  989.     struct timeval endtime;    /* time job exited */
  990. };
  991.  
  992. /* node in alias hash table */
  993.  
  994. struct alias {
  995.     struct hashnode *next;
  996.     char *nam;            /* hash data */
  997.     char *text;            /* expansion of alias */
  998.     int cmd;            /* one for regular aliases, zero for global
  999.                    aliases, negative for reserved words */ 
  1000.     int inuse;            /* alias is being expanded */
  1001. };
  1002.  
  1003. /* node in sched list */
  1004.  
  1005. struct schedcmd {
  1006.     struct schedcmd *next;
  1007.     char *cmd;            /* command to run */
  1008.     time_t time;        /* when to run it */
  1009. };
  1010.  
  1011. #define MAXAL 20    /* maximum number of aliases expanded at once */
  1012.  
  1013. /* hash table node */
  1014.  
  1015. struct hashnode {
  1016.     struct hashnode *next;
  1017.     char *nam;
  1018. };
  1019.  
  1020. /* hash table */
  1021.  
  1022. struct hashtab {
  1023.     int hsize;            /* size of nodes[] */
  1024.     int ct;            /* # of elements */
  1025.     struct hashnode **nodes;    /* array of size hsize */
  1026. };
  1027.  
  1028. /* history entry */
  1029.  
  1030. struct histent {
  1031.     char *lex;            /* lexical history line */
  1032.     char *lit;            /* literal history line */
  1033.     time_t stim;        /* command started time (datestamp) */
  1034.     time_t ftim;        /* command finished time */
  1035.     int flags;            /* Misc flags */
  1036. };
  1037.  
  1038. #define HIST_OLD    0x00000001    /* Command is already written to disk*/
  1039.  
  1040. /* completion control */
  1041.  
  1042. struct compcond {
  1043.     struct compcond *and, *or;    /* the next or'ed/and'ed conditions */
  1044.     int type, n;        /* the type (CCT_*) and the array length */
  1045.     union {            /* these structs hold the data used to */
  1046.     struct {        /* test this condition */
  1047.         int *a, *b;        /* CCT_POS, CCT_NUMWORDS */
  1048.     }
  1049.     r;
  1050.     struct {        /* CCT_CURSTR, CCT_CURPAT,... */
  1051.         int *p;
  1052.         char **s;
  1053.     }
  1054.     s;
  1055.     struct {        /* CCT_RANGESTR,... */
  1056.         char **a, **b;
  1057.     }
  1058.     l;
  1059.     }
  1060.     u;
  1061. };
  1062.  
  1063. #define CCT_UNUSED     0
  1064. #define CCT_POS        1
  1065. #define CCT_CURSTR     2
  1066. #define CCT_CURPAT     3
  1067. #define CCT_WORDSTR    4
  1068. #define CCT_WORDPAT    5
  1069. #define CCT_CURSUF     6
  1070. #define CCT_CURPRE     7
  1071. #define CCT_CURSUB     8
  1072. #define CCT_CURSUBC    9
  1073. #define CCT_NUMWORDS  10
  1074. #define CCT_RANGESTR  11
  1075. #define CCT_RANGEPAT  12
  1076.  
  1077. struct compctlp {        /* the hash table node for compctls */
  1078.     struct hashnode *next;
  1079.     char *nam;            /* command name */
  1080.     Compctl cc;            /* pointer to the compctl desc. */
  1081. };
  1082.  
  1083. struct compctl {        /* the real desc. for compctls */
  1084.     int refc;            /* reference count */
  1085.     struct compctl *next;    /* next compctl for -x */
  1086.     unsigned long mask;        /* mask of things to complete (CC_*) */
  1087.     char *keyvar;        /* for -k (variable) */
  1088.     char *glob;            /* for -g (globbing) */
  1089.     char *str;            /* for -s (expansion) */
  1090.     char *func;            /* for -f (function) */
  1091.     char *explain;        /* for -X (explanation) */
  1092.     char *prefix, *suffix;    /* for -P and -S (prefix, suffix) */
  1093.     char *subcmd;        /* for -l (command name to use) */
  1094.     char *hpat;            /* for -H (history pattern) */
  1095.     int hnum;            /* for -H (number of events to search) */
  1096.     struct compctl *ext;    /* for -x (first of the compctls after -x) */
  1097.     struct compcond *cond;    /* for -x (condition for this compctl) */
  1098.     struct compctl *xor;    /* for + (next of the xor'ed compctls) */
  1099. };
  1100.  
  1101. #define CC_FILES    (1<<0)
  1102. #define CC_COMMPATH    (1<<1)
  1103. #define CC_REMOVE       (1<<2)
  1104. #define CC_OPTIONS    (1<<3)
  1105. #define CC_VARS        (1<<4)
  1106. #define CC_BINDINGS    (1<<5)
  1107. #define CC_ARRAYS    (1<<6)
  1108. #define CC_INTVARS    (1<<7)
  1109. #define CC_FUNCS    (1<<8)
  1110. #define CC_PARAMS    (1<<9)
  1111. #define CC_ENVVARS    (1<<10)
  1112. #define CC_JOBS        (1<<11)
  1113. #define CC_RUNNING    (1<<12)
  1114. #define CC_STOPPED    (1<<13)
  1115. #define CC_BUILTINS    (1<<14)
  1116. #define CC_ALREG    (1<<15)
  1117. #define CC_ALGLOB    (1<<16)
  1118. #define CC_USERS    (1<<17)
  1119. #define CC_DISCMDS    (1<<18)
  1120. #define CC_EXCMDS    (1<<19)
  1121. #define CC_SCALARS    (1<<20)
  1122. #define CC_READONLYS    (1<<21)
  1123. #define CC_SPECIALS    (1<<22)
  1124. #define CC_DELETE       (1<<23)
  1125.  
  1126. #define CC_RESERVED     (1<<31)
  1127.  
  1128. #include <errno.h>
  1129. extern char *sys_errlist[];
  1130. extern int sys_nerr;
  1131. extern int errno;
  1132.  
  1133. /* values in opts[] array */
  1134.  
  1135. #define OPT_INVALID 1        /* opt is invalid, like -$ */
  1136. #define OPT_UNSET 0
  1137. #define OPT_SET 2
  1138.  
  1139. /* the options */
  1140.  
  1141. struct option {
  1142.     char *name;
  1143.     char id;            /* corresponding letter */
  1144. };
  1145.  
  1146. #define CORRECT '0'
  1147. #define NOCLOBBER '1'
  1148. #define NOBADPATTERN '2'
  1149. #define NONOMATCH '3'
  1150. #define GLOBDOTS '4'
  1151. #define NOTIFY '5'
  1152. #define BGNICE '6'
  1153. #define IGNOREEOF '7'
  1154. #define MARKDIRS '8'
  1155. #define AUTOLIST '9'
  1156. #define NOBEEP 'B'
  1157. #define PRINTEXITVALUE 'C'
  1158. #define PUSHDTOHOME 'D'
  1159. #define PUSHDSILENT 'E'
  1160. #define NOGLOBOPT 'F'
  1161. #define NULLGLOB 'G'
  1162. #define RMSTARSILENT 'H'
  1163. #define IGNOREBRACES 'I'
  1164. #define AUTOCD 'J'
  1165. #define NOBANGHIST 'K'
  1166. #define SUNKEYBOARDHACK 'L'
  1167. #define SINGLELINEZLE 'M'
  1168. #define AUTOPUSHD 'N'
  1169. #define CORRECTALL 'O'
  1170. #define RCEXPANDPARAM 'P'
  1171. #define PATHDIRS 'Q'
  1172. #define LONGLISTJOBS 'R'
  1173. #define RECEXACT 'S'
  1174. #define CDABLEVARS 'T'
  1175. #define MAILWARNING 'U'
  1176. #define NOPROMPTCR 'V'
  1177. #define AUTORESUME 'W'
  1178. #define LISTTYPES 'X'
  1179. #define MENUCOMPLETE 'Y'
  1180. #define USEZLE 'Z'
  1181. #define ALLEXPORT 'a'
  1182. #define ERREXIT 'e'
  1183. #define NORCS 'f'
  1184. #define HISTIGNORESPACE 'g'
  1185. #define HISTIGNOREDUPS 'h'
  1186. #define INTERACTIVE 'i'
  1187. #define HISTLIT 'j'
  1188. #define INTERACTIVECOMMENTS 'k'
  1189. #define LOGINSHELL 'l'
  1190. #define MONITOR 'm'
  1191. #define NOEXEC 'n'
  1192. #define SHINSTDIN 's'
  1193. #define NOUNSET 'u'
  1194. #define VERBOSE 'v'
  1195. #define CHASELINKS 'w'
  1196. #define XTRACE 'x'
  1197. #define SHWORDSPLIT 'y'
  1198. #define HISTNOSTORE '\3'
  1199. #define EXTENDEDGLOB '\5'
  1200. #define GLOBCOMPLETE '\6'
  1201. #define CSHJUNKIEQUOTES '\7'
  1202. #define PUSHDMINUS '\10'
  1203. #define CSHJUNKIELOOPS '\11'
  1204. #define RCQUOTES '\12'
  1205. #define KSHOPTIONPRINT '\13'
  1206. #define NOSHORTLOOPS '\14'
  1207. #define COMPLETEINWORD '\15'
  1208. #define AUTOMENU '\16'
  1209. #define HISTVERIFY '\17'
  1210. #define NOLISTBEEP '\20'
  1211. #define NOHUP '\21'
  1212. #define NOEQUALS '\22'
  1213. #define CSHNULLGLOB '\23'
  1214. #define HASHCMDS '\24'
  1215. #define HASHDIRS '\25'
  1216. #define NUMERICGLOBSORT '\26'
  1217. #define BRACECCL '\27'
  1218. #define HASHLISTALL '\30'
  1219. #define OVERSTRIKE '\31'
  1220. #define NOHISTBEEP '\32'
  1221. #define PUSHDIGNOREDUPS '\33'
  1222. #define AUTOREMOVESLASH '\34'
  1223. #define EXTENDEDHISTORY '\35'
  1224. #define APPENDHISTORY '\36'
  1225. #define CSHJUNKIEHISTORY '\037'
  1226. #define MAGICEQUALSUBST '\040'
  1227. #define CSHJUNKIETILDE '\041'
  1228. #define PROMPTSUBST '\043'
  1229. #define ALWAYSLASTPROMPT '\044'
  1230. #define COMPLETEALIASES '\045'
  1231. #define AUTOPARAMKEYS '\046'
  1232. #define ALWAYSTOEND '\047'
  1233. #define NOFLOWCONTROL '\050'
  1234. #define LISTAMBIGUOUS '\051'
  1235. #define AUTONAMEDIRS '\052'
  1236.  
  1237.  
  1238. #ifndef GLOBALS
  1239. extern struct option optns[];
  1240.  
  1241. #else
  1242. struct option optns[] =
  1243. {
  1244.     {"correct", CORRECT},
  1245.     {"noclobber", NOCLOBBER},
  1246.     {"nobadpattern", NOBADPATTERN},
  1247.     {"nonomatch", NONOMATCH},
  1248.     {"globdots", GLOBDOTS},
  1249.     {"notify", NOTIFY},
  1250.     {"bgnice", BGNICE},
  1251.     {"ignoreeof", IGNOREEOF},
  1252.     {"markdirs", MARKDIRS},
  1253.     {"autolist", AUTOLIST},
  1254.     {"nobeep", NOBEEP},
  1255.     {"printexitvalue", PRINTEXITVALUE},
  1256.     {"pushdtohome", PUSHDTOHOME},
  1257.     {"pushdsilent", PUSHDSILENT},
  1258.     {"noglob", NOGLOBOPT},
  1259.     {"nullglob", NULLGLOB},
  1260.     {"rmstarsilent", RMSTARSILENT},
  1261.     {"ignorebraces", IGNOREBRACES},
  1262.     {"braceccl", BRACECCL},
  1263.     {"autocd", AUTOCD},
  1264.     {"nobanghist", NOBANGHIST},
  1265.     {"sunkeyboardhack", SUNKEYBOARDHACK},
  1266.     {"singlelinezle", SINGLELINEZLE},
  1267.     {"autopushd", AUTOPUSHD},
  1268.     {"correctall", CORRECTALL},
  1269.     {"rcexpandparam", RCEXPANDPARAM},
  1270.     {"pathdirs", PATHDIRS},
  1271.     {"longlistjobs", LONGLISTJOBS},
  1272.     {"recexact", RECEXACT},
  1273.     {"cdablevars", CDABLEVARS},
  1274.     {"mailwarning", MAILWARNING},
  1275.     {"nopromptcr", NOPROMPTCR},
  1276.     {"autoresume", AUTORESUME},
  1277.     {"listtypes", LISTTYPES},
  1278.     {"menucomplete", MENUCOMPLETE},
  1279.     {"zle", USEZLE},
  1280.     {"allexport", ALLEXPORT},
  1281.     {"errexit", ERREXIT},
  1282.     {"norcs", NORCS},
  1283.     {"histignorespace", HISTIGNORESPACE},
  1284.     {"histignoredups", HISTIGNOREDUPS},
  1285.     {"interactive", INTERACTIVE},
  1286.     {"histlit", HISTLIT},
  1287.     {"interactivecomments", INTERACTIVECOMMENTS},
  1288.     {"login", LOGINSHELL},
  1289.     {"monitor", MONITOR},
  1290.     {"noexec", NOEXEC},
  1291.     {"shinstdin", SHINSTDIN},
  1292.     {"nounset", NOUNSET},
  1293.     {"verbose", VERBOSE},
  1294.     {"chaselinks", CHASELINKS},
  1295.     {"xtrace", XTRACE},
  1296.     {"shwordsplit", SHWORDSPLIT},
  1297.     {"histnostore", HISTNOSTORE},
  1298.     {"extendedglob", EXTENDEDGLOB},
  1299.     {"globcomplete", GLOBCOMPLETE},
  1300.     {"cshjunkiequotes", CSHJUNKIEQUOTES},
  1301.     {"pushdminus", PUSHDMINUS},
  1302.     {"cshjunkieloops", CSHJUNKIELOOPS},
  1303.     {"rcquotes", RCQUOTES},
  1304.     {"noshortloops", NOSHORTLOOPS},
  1305.     {"completeinword", COMPLETEINWORD},
  1306.     {"automenu", AUTOMENU},
  1307.     {"histverify", HISTVERIFY},
  1308.     {"nolistbeep", NOLISTBEEP},
  1309.     {"nohup", NOHUP},
  1310.     {"noequals", NOEQUALS},
  1311.     {"kshoptionprint", KSHOPTIONPRINT},
  1312.     {"cshnullglob", CSHNULLGLOB},
  1313.     {"hashcmds", HASHCMDS},
  1314.     {"hashdirs", HASHDIRS},
  1315.     {"numericglobsort", NUMERICGLOBSORT},
  1316.     {"hashlistall", HASHLISTALL},
  1317.     {"overstrike", OVERSTRIKE},
  1318.     {"nohistbeep", NOHISTBEEP},
  1319.     {"pushdignoredups", PUSHDIGNOREDUPS},
  1320.     {"autoremoveslash", AUTOREMOVESLASH},
  1321.     {"extendedhistory", EXTENDEDHISTORY},
  1322.     {"appendhistory", APPENDHISTORY},
  1323.     {"cshjunkiehistory", CSHJUNKIEHISTORY},
  1324.     {"magicequalsubst", MAGICEQUALSUBST},
  1325.     {"cshjunkietilde", CSHJUNKIETILDE},
  1326.     {"promptsubst", PROMPTSUBST},
  1327.     {"alwayslastprompt", ALWAYSLASTPROMPT},
  1328.     {"completealiases", COMPLETEALIASES},
  1329.     {"autoparamkeys", AUTOPARAMKEYS},
  1330.     {"alwaystoend", ALWAYSTOEND},
  1331.     {"noflowcontrol", NOFLOWCONTROL},
  1332.     {"listambiguous", LISTAMBIGUOUS},
  1333.     {"autonamedirs", AUTONAMEDIRS},
  1334.     {NULL, 0}
  1335. };
  1336.  
  1337. #endif
  1338.  
  1339. #define ALSTAT_MORE 1        /* last alias ended with ' ' */
  1340. #define ALSTAT_JUNK 2        /* don't put word in history List */
  1341.  
  1342. #undef isset
  1343. #define isset(X) (opts[(int)X] == OPT_SET)
  1344. #define unset(X) (opts[(int)X] == OPT_UNSET)
  1345. #define interact (isset(INTERACTIVE))
  1346. #define jobbing (isset(MONITOR))
  1347. #define jobbingv opts[MONITOR]
  1348. #define islogin (isset(LOGINSHELL))
  1349.  
  1350. #ifndef SYSVR4
  1351. #ifndef _IBMR2
  1352. #undef WIFSTOPPED
  1353. #undef WIFSIGNALED
  1354. #undef WIFEXITED
  1355. #undef WEXITSTATUS
  1356. #undef WTERMSIG
  1357. #undef WSTOPSIG
  1358. #undef WCOREDUMP
  1359.  
  1360. #define WIFSTOPPED(X) (((X)&0377)==0177)
  1361. #define WIFSIGNALED(X) (((X)&0377)!=0&&((X)&0377)!=0177)
  1362. #define WIFEXITED(X) (((X)&0377)==0)
  1363. #define WEXITSTATUS(X) (((X)>>8)&0377)
  1364. #define WTERMSIG(X) ((X)&0177)
  1365. #define WSTOPSIG(X) (((X)>>8)&0377)
  1366. #endif
  1367. #if !defined(IRIX5) || !defined(_POSIX_SOURCE)
  1368. #define WCOREDUMP(X) ((X)&0200)
  1369. #endif
  1370. #endif
  1371.  
  1372. #if defined(IRIX5) && defined(_POSIX_SOURCE)
  1373. #define WCOREDUMP(X) ((*(int *)&(X)) & 0200)
  1374. #endif
  1375.  
  1376. #ifndef S_ISBLK
  1377. #define    _IFMT        0170000
  1378. #define    _IFDIR    0040000
  1379. #define    _IFCHR    0020000
  1380. #define    _IFBLK    0060000
  1381. #define    _IFREG    0100000
  1382. #define    _IFIFO    0010000
  1383. #define    S_ISBLK(m)    (((m)&_IFMT) == _IFBLK)
  1384. #define    S_ISCHR(m)    (((m)&_IFMT) == _IFCHR)
  1385. #define    S_ISDIR(m)    (((m)&_IFMT) == _IFDIR)
  1386. #define    S_ISFIFO(m)    (((m)&_IFMT) == _IFIFO)
  1387. #define    S_ISREG(m)    (((m)&_IFMT) == _IFREG)
  1388. #endif
  1389.  
  1390. #ifndef _IFMT
  1391. #define _IFMT 0170000
  1392. #endif
  1393.  
  1394. #ifndef S_ISSOCK
  1395. #define    _IFSOCK    0140000
  1396. #define    S_ISSOCK(m)    (((m)&_IFMT) == _IFSOCK)
  1397. #endif
  1398.  
  1399. #ifndef S_ISLNK
  1400. #define    _IFLNK    0120000
  1401. #define    S_ISLNK(m)    (((m)&_IFMT) == _IFLNK)
  1402. #endif
  1403.  
  1404. #if S_IFIFO == S_IFSOCK
  1405. #undef S_IFIFO
  1406. #endif
  1407.  
  1408. #ifndef S_IFIFO
  1409. #undef HAS_FIFOS
  1410. #endif
  1411.  
  1412. /* buffered shell input for non-interactive shells */
  1413.  
  1414. EXTERN FILE *bshin;
  1415.  
  1416. /* NULL-terminated arrays containing path, cdpath, etc. */
  1417.  
  1418. EXTERN char **path, **cdpath, **fpath, **watch, **mailpath;
  1419. EXTERN char **manpath, **tildedirs, **fignore;
  1420. EXTERN char **psvar;
  1421.  
  1422. /* named directories */
  1423.  
  1424. typedef struct nameddirs *Nameddirs;
  1425.  
  1426. struct nameddirs {
  1427.     int len;            /* length of path namdirs[t0].dir */
  1428.     int namelen;        /* length of name */
  1429.     char *name;
  1430.     char *dir;
  1431.     int homedir;        /* is this name a home directory? */
  1432. };
  1433.  
  1434. EXTERN struct nameddirs *namdirs;
  1435.  
  1436. /* size of userdirs[], # of userdirs */
  1437.  
  1438. EXTERN int userdirsz, userdirct;
  1439.  
  1440. EXTERN char *mailfile;
  1441.  
  1442. EXTERN char *yytext;
  1443.  
  1444. /* error/break flag */
  1445.  
  1446. EXTERN int errflag;
  1447.  
  1448. /* Status of return from a trap */
  1449.  
  1450. EXTERN int trapreturn;
  1451.  
  1452. EXTERN char *tokstr;
  1453. EXTERN int tok, tokfd;
  1454.  
  1455. /* lexical analyzer error flag */
  1456.  
  1457. EXTERN int lexstop;
  1458.  
  1459. /* suppress error messages */
  1460.  
  1461. EXTERN int noerrs;
  1462.  
  1463. /* nonzero means we are not evaluating, just parsing (in math.c) */
  1464.  
  1465. EXTERN int noeval;
  1466.  
  1467. /* current history event number */
  1468.  
  1469. EXTERN int curhist;
  1470.  
  1471. /* if != 0, this is the first line of the command */
  1472.  
  1473. EXTERN int isfirstln;
  1474.  
  1475. /* if != 0, this is the first char of the command (not including
  1476.     white space) */
  1477.  
  1478. EXTERN int isfirstch;
  1479.  
  1480. /* number of history entries */
  1481.  
  1482. EXTERN int histentct;
  1483.  
  1484. /* array of history entries */
  1485.  
  1486. EXTERN Histent histentarr;
  1487.  
  1488. /* capacity of history lists */
  1489.  
  1490. EXTERN int histsiz, lithistsiz;
  1491.  
  1492. /* if = 1, we have performed history substitution on the current line
  1493.      if = 2, we have used the 'p' modifier */
  1494.  
  1495. EXTERN int histdone;
  1496.  
  1497. /* default event (usually curhist-1, that is, "!!") */
  1498.  
  1499. EXTERN int defev;
  1500.  
  1501. /* != 0 if we are about to read a command word */
  1502.  
  1503. EXTERN int incmdpos;
  1504.  
  1505. /* != 0 if we are in the middle of a [[ ... ]] */
  1506.  
  1507. EXTERN int incond;
  1508.  
  1509. /* != 0 if we are after a redirection (for ctxtlex only) */
  1510.  
  1511. EXTERN int inredir;
  1512.  
  1513. /* != 0 if we are about to read a case pattern */
  1514.  
  1515. EXTERN int incasepat;
  1516.  
  1517. /* != 0 if we just read FUNCTION */
  1518.  
  1519. EXTERN int infunc;
  1520.  
  1521. /* != 0 if we just read a newline */
  1522.  
  1523. EXTERN int isnewlin;
  1524.  
  1525. /* the lists of history events */
  1526.  
  1527. EXTERN Lklist histlist, lithistlist;
  1528.  
  1529. /* the directory stack */
  1530.  
  1531. EXTERN Lklist dirstack;
  1532.  
  1533. /* the zle buffer stack */
  1534.  
  1535. EXTERN Lklist bufstack;
  1536.  
  1537. /* the input queue (stack?)
  1538.  
  1539.     inbuf    = start of buffer
  1540.     inbufptr = location in buffer    (= inbuf for a FULL buffer)
  1541.                     (= inbuf+inbufsz for an EMPTY buffer)
  1542.     inbufct  = # of chars in buffer (inbufptr+inbufct == inbuf+inbufsz)
  1543.     inbufsz  = max size of buffer
  1544. */
  1545.  
  1546. EXTERN char *inbuf, *inbufptr;
  1547. EXTERN int inbufct, inbufsz;
  1548.  
  1549. EXTERN char *ifs;        /* $IFS */
  1550.  
  1551. EXTERN char *oldpwd;        /* $OLDPWD */
  1552.  
  1553. EXTERN char *underscore;    /* $_ */
  1554.  
  1555. /* != 0 if this is a subshell */
  1556.  
  1557. EXTERN int subsh;
  1558.  
  1559. /* # of break levels */
  1560.  
  1561. EXTERN int breaks;
  1562.  
  1563. /* != 0 if we have a return pending */
  1564.  
  1565. EXTERN int retflag;
  1566.  
  1567. /* how far we've hashed the PATH so far */
  1568.  
  1569. EXTERN char **pathchecked;
  1570.  
  1571. /* # of nested loops we are in */
  1572.  
  1573. EXTERN int loops;
  1574.  
  1575. /* # of continue levels */
  1576.  
  1577. EXTERN int contflag;
  1578.  
  1579. /* the job we are working on */
  1580.  
  1581. EXTERN int thisjob;
  1582.  
  1583. /* the current job (+) */
  1584.  
  1585. EXTERN int curjob;
  1586.  
  1587. /* the previous job (-) */
  1588.  
  1589. EXTERN int prevjob;
  1590.  
  1591. /* hash table containing the aliases and reserved words */
  1592.  
  1593. EXTERN Hashtab aliastab;
  1594.  
  1595. /* hash table containing the parameters */
  1596.  
  1597. EXTERN Hashtab paramtab;
  1598.  
  1599. /* hash table containing the builtins/shfuncs/hashed commands */
  1600.  
  1601. EXTERN Hashtab cmdnamtab;
  1602.  
  1603. /* hash table for completion info for commands */
  1604.  
  1605. EXTERN Hashtab compctltab;
  1606.  
  1607. /* default completion infos */
  1608.  
  1609. EXTERN struct compctl cc_compos, cc_default, cc_dummy;
  1610.  
  1611. /* the job table */
  1612.  
  1613. EXTERN struct job jobtab[MAXJOB];
  1614.  
  1615. /* shell timings */
  1616.  
  1617. #ifndef HAS_RUSAGE
  1618. EXTERN struct tms shtms;
  1619.  
  1620. #endif
  1621.  
  1622. /* the list of sched jobs pending */
  1623.  
  1624. EXTERN struct schedcmd *schedcmds;
  1625.  
  1626. /* the last l for s/l/r/ history substitution */
  1627.  
  1628. EXTERN char *hsubl;
  1629.  
  1630. /* the last r for s/l/r/ history substitution */
  1631.  
  1632. EXTERN char *hsubr;
  1633.  
  1634. EXTERN char *username;        /* $USERNAME */
  1635. EXTERN char *zlogname;        /* $LOGNAME */
  1636. EXTERN long lastval;        /* $? */
  1637. EXTERN long baud;        /* $BAUD */
  1638. EXTERN long columns;        /* $COLUMNS */
  1639. EXTERN long lines;        /* $LINES */
  1640. EXTERN long reporttime;        /* $REPORTTIME */
  1641.  
  1642. /* input fd from the coprocess */
  1643.  
  1644. EXTERN int coprocin;
  1645.  
  1646. /* output fd from the coprocess */
  1647.  
  1648. EXTERN int coprocout;
  1649.  
  1650. EXTERN long mailcheck;        /* $MAILCHECK */
  1651. EXTERN long logcheck;        /* $LOGCHECK */
  1652.  
  1653. /* the last time we checked mail */
  1654.  
  1655. EXTERN time_t lastmailcheck;
  1656.  
  1657. /* the last time we checked the people in the WATCH variable */
  1658.  
  1659. EXTERN time_t lastwatch;
  1660.  
  1661. /* the last time we did the periodic() shell function */
  1662.  
  1663. EXTERN time_t lastperiod;
  1664.  
  1665. /* $SECONDS = time(NULL) - shtimer.tv_sec */
  1666.  
  1667. EXTERN struct timeval shtimer;
  1668.  
  1669. EXTERN long mypid;        /* $$ */
  1670. EXTERN long lastpid;        /* $! */
  1671. EXTERN long ppid;        /* $PPID */
  1672.  
  1673. /* the process group of the shell */
  1674.  
  1675. EXTERN long mypgrp;
  1676.  
  1677. EXTERN char *pwd;        /* $PWD */
  1678. EXTERN char *zoptarg;        /* $OPTARG */
  1679. EXTERN long zoptind;        /* $OPTIND */
  1680. EXTERN char *prompt;        /* $PROMPT */
  1681. EXTERN char *rprompt;        /* $RPROMPT */
  1682. EXTERN char *prompt2;        /* etc. */
  1683. EXTERN char *prompt3;
  1684. EXTERN char *prompt4;
  1685. EXTERN char *sprompt;
  1686. EXTERN char *timefmt;
  1687. EXTERN char *watchfmt;
  1688. EXTERN char *wordchars;
  1689. EXTERN char *fceditparam;
  1690. EXTERN char *tmpprefix;
  1691. EXTERN char *rstring, *Rstring;
  1692. EXTERN char *postedit;
  1693.  
  1694. EXTERN char *argzero;        /* $0 */
  1695.  
  1696. EXTERN char *hackzero;
  1697.  
  1698. /* the hostname */
  1699.  
  1700. EXTERN char *hostnam;
  1701.  
  1702. EXTERN char *home;        /* $HOME */
  1703. EXTERN char **pparams;        /* $argv */
  1704.  
  1705. /* the default command for null commands */
  1706.  
  1707. EXTERN char *nullcmd;
  1708. EXTERN char *readnullcmd;
  1709.  
  1710. /* the List of local variables we have to destroy */
  1711.  
  1712. EXTERN Lklist locallist;
  1713.  
  1714. /* what level of localness we are at */
  1715.  
  1716. EXTERN int locallevel;
  1717.  
  1718. /* what level of sourcing we are at */
  1719.  
  1720. EXTERN int sourcelevel;
  1721.  
  1722. /* the shell input fd */
  1723.  
  1724. EXTERN int SHIN;
  1725.  
  1726. /* the shell tty fd */
  1727.  
  1728. EXTERN int SHTTY;
  1729.  
  1730. /* the stack of aliases we are expanding */
  1731.  
  1732. EXTERN struct alias *alstack[MAXAL];
  1733.  
  1734. /* the alias stack pointer; also, the number of aliases currently
  1735.      being expanded */
  1736.  
  1737. EXTERN int alstackind;
  1738.  
  1739. /* != 0 means we are reading input from a string */
  1740.  
  1741. EXTERN int strin;
  1742.  
  1743. /* period between periodic() commands, in seconds */
  1744.  
  1745. EXTERN long period;
  1746.  
  1747. /* != 0 means history substitution is turned off */
  1748.  
  1749. EXTERN int stophist;
  1750.  
  1751. EXTERN int lithist;
  1752.  
  1753. /* this line began with a space, so junk it if HISTIGNORESPACE is on */
  1754.  
  1755. EXTERN int spaceflag;
  1756.  
  1757. /* don't do spelling correction */
  1758.  
  1759. EXTERN int nocorrect;
  1760.  
  1761. /* != 0 means we have removed the current event from the history List */
  1762.  
  1763. EXTERN int histremmed;
  1764.  
  1765. /* the options; e.g. if opts['a'] == OPT_SET, -a is turned on */
  1766.  
  1767. EXTERN int opts[128];
  1768.  
  1769. EXTERN long keytimeout;        /* KEYTIMEOUT */
  1770. EXTERN long lineno;        /* LINENO */
  1771. EXTERN long listmax;        /* LISTMAX */
  1772. EXTERN long savehist;        /* SAVEHIST */
  1773. EXTERN long shlvl;        /* SHLVL */
  1774. EXTERN long tmout;        /* TMOUT */
  1775. EXTERN long dirstacksize;    /* DIRSTACKSIZE */
  1776.  
  1777. /* != 0 means we have called execlist() and then intend to exit(),
  1778.      so don't fork if not necessary */
  1779.  
  1780. EXTERN int exiting;
  1781.  
  1782. EXTERN int lastbase;        /* last input base we used */
  1783.  
  1784. /* the limits for child processes */
  1785.  
  1786. #ifdef RLIM_INFINITY
  1787. EXTERN struct rlimit limits[RLIM_NLIMITS];
  1788.  
  1789. #endif
  1790.  
  1791. /* the current word in the history List */
  1792.  
  1793. EXTERN char *hlastw;
  1794.  
  1795. /* pointer into the history line */
  1796.  
  1797. EXTERN char *hptr;
  1798.  
  1799. /* the current history line */
  1800.  
  1801. EXTERN char *chline;
  1802.  
  1803. /* the termcap buffer */
  1804.  
  1805. EXTERN char termbuf[1024];
  1806.  
  1807. /* $TERM */
  1808.  
  1809. EXTERN char *term;
  1810.  
  1811. /* != 0 if this $TERM setup is usable */
  1812.  
  1813. EXTERN int termok;
  1814.  
  1815. /* flag for CSHNULLGLOB */
  1816.  
  1817. EXTERN int badcshglob;
  1818.  
  1819. /* max size of histline */
  1820.  
  1821. EXTERN int hlinesz;
  1822.  
  1823. /* the alias expansion status - if == ALSTAT_MORE, we just finished
  1824.     expanding an alias ending with a space */
  1825.  
  1826. EXTERN int alstat;
  1827.  
  1828. /* we have printed a 'you have stopped (running) jobs.' message */
  1829.  
  1830. EXTERN int stopmsg;
  1831.  
  1832. /* the default tty state */
  1833.  
  1834. EXTERN struct ttyinfo shttyinfo;
  1835.  
  1836. /* $TTY */
  1837.  
  1838. EXTERN char *ttystrname;
  1839.  
  1840. /* 1 if ttyctl -f has been executed */
  1841.  
  1842. EXTERN int ttyfrozen;
  1843.  
  1844. /* != 0 if we are allocating in the heaplist */
  1845.  
  1846. EXTERN int useheap;
  1847.  
  1848. /* Words on the command line, for use in completion */
  1849.  
  1850. EXTERN int clwsize, clwnum, clwpos;
  1851. EXTERN char **clwords;
  1852.  
  1853. /* pid of process undergoing 'process substitution' */
  1854.  
  1855. EXTERN int cmdoutpid;
  1856.  
  1857. /* exit status of process undergoing 'process substitution' */
  1858.  
  1859. EXTERN int cmdoutval;
  1860.  
  1861. /* 1 if aliases should not be expanded */
  1862.  
  1863. EXTERN int noaliases;
  1864.  
  1865. #include "signals.h"
  1866.  
  1867. #ifdef GLOBALS
  1868.  
  1869. /* signal names */
  1870. char **sigptr = sigs;
  1871.  
  1872. /* tokens */
  1873. char *ztokens = "#$^*()$=|{}[]`<>?~`,'\"\\";
  1874.  
  1875. #else
  1876. extern char *ztokens, **sigptr;
  1877.  
  1878. #endif
  1879.  
  1880. #define SIGZERR (SIGCOUNT+1)
  1881. #define SIGDEBUG (SIGCOUNT+2)
  1882. #define VSIGCOUNT (SIGCOUNT+3)
  1883. #define SIGEXIT 0
  1884.  
  1885. /* signals that are trapped = 1, signals ignored =2 */
  1886.  
  1887. EXTERN int sigtrapped[VSIGCOUNT];
  1888.  
  1889. /* trap functions for each signal */
  1890.  
  1891. EXTERN List sigfuncs[VSIGCOUNT];
  1892.  
  1893. /* $HISTCHARS */
  1894.  
  1895. EXTERN unsigned char bangchar, hatchar, hashchar;
  1896.  
  1897. EXTERN int eofseen;
  1898.  
  1899. /* we are parsing a line sent to use by the editor */
  1900.  
  1901. EXTERN int zleparse;
  1902.  
  1903. EXTERN int wordbeg;
  1904.  
  1905. EXTERN int parbegin;
  1906.  
  1907. /* used in arrays of lists instead of NULL pointers */
  1908.  
  1909. EXTERN struct list dummy_list;
  1910.  
  1911. /* interesting termcap strings */
  1912.  
  1913. #define TCCLEARSCREEN 0
  1914. #define TCLEFT 1
  1915. #define TCMULTLEFT 2
  1916. #define TCRIGHT 3
  1917. #define TCMULTRIGHT 4
  1918. #define TCUP 5
  1919. #define TCMULTUP 6
  1920. #define TCDOWN 7
  1921. #define TCMULTDOWN 8
  1922. #define TCDEL 9
  1923. #define TCMULTDEL 10
  1924. #define TCINS 11
  1925. #define TCMULTINS 12
  1926. #define TCCLEAREOD 13
  1927. #define TCCLEAREOL 14
  1928. #define TCINSLINE 15
  1929. #define TCDELLINE 16
  1930. #define TCNEXTTAB 17
  1931. #define TC_COUNT 18
  1932.  
  1933. /* lengths of each string */
  1934.  
  1935. EXTERN int tclen[TC_COUNT];
  1936.  
  1937. EXTERN char *tcstr[TC_COUNT];
  1938.  
  1939. #ifdef GLOBALS
  1940.  
  1941. /* names of the strings we want */
  1942.  
  1943. char *tccapnams[TC_COUNT] =
  1944. {
  1945.     "cl", "le", "LE", "nd", "RI", "up", "UP", "do",
  1946.     "DO", "dc", "DC", "ic", "IC", "cd", "ce", "al", "dl", "ta"
  1947. };
  1948.  
  1949. #else
  1950. extern char *tccapnams[TC_COUNT];
  1951.  
  1952. #endif
  1953.  
  1954. #define tccan(X) (tclen[X])
  1955.  
  1956. #define HISTFLAG_DONE   1
  1957. #define HISTFLAG_NOEXEC 2
  1958. #define HISTFLAG_RECALL 4
  1959.  
  1960. #ifdef HAS_SETPGID
  1961. #define setpgrp setpgid
  1962. #endif
  1963.  
  1964. #define _INCLUDE_POSIX_SOURCE
  1965. #define _INCLUDE_XOPEN_SOURCE
  1966. #define _INCLUDE_HPUX_SOURCE
  1967.  
  1968. #ifdef SV_BSDSIG
  1969. #define SV_INTERRUPT SV_BSDSIG
  1970. #endif
  1971.  
  1972. #if defined(POSIX) || !defined(SYSV)
  1973. #define SIGNAL_MASKS
  1974. #endif
  1975.  
  1976. #ifndef POSIX
  1977. typedef unsigned int sigset_t;
  1978. typedef unsigned int mode_t;
  1979. #define sigemptyset(s)    (*(s) = 0)
  1980. #if NSIG == 32
  1981. #define sigfillset(s)     ((*(s) = 0xffffffff), 0)
  1982. #else
  1983. #define sigfillset(s)     ((*(s) = (1 << NSIG) - 1), 0)
  1984. #endif
  1985. #define z_sigmask(n)      (1 << ((n) - 1))
  1986. #define sigaddset(s,n)    ((*(s) |= z_sigmask(n)), 0) 
  1987. #define sigdelset(s,n)    ((*(s) &= ~z_sigmask(n)), 0)
  1988. #define sigismember(s,n)  ((*(s) & z_sigmask(n)) ? 1 : 0)
  1989. #endif
  1990.  
  1991. #define blockchld()        sig_block(sig_mask(SIGCHLD))
  1992. #define unblockchld()      sig_unblock(sig_mask(SIGCHLD))
  1993. #define chldpause()        sig_suspend(SIGCHLD)
  1994.  
  1995. #ifdef SIGNAL_MASKS
  1996. #define fast_block(s)      (void)(*(s) = sig_block(sig_notmask(0)))
  1997. #define fast_unblock(s)    (void)sig_setmask(*(s))
  1998. #else
  1999. #define fast_block(s)      (void)sigemptyset(s)
  2000. #define fast_unblock(s)    (void)(s)
  2001. #endif
  2002.  
  2003. EXTERN int zigsig, zigblock;
  2004. EXTERN sigset_t zigmask;
  2005.  
  2006. #define zigunsafe()    (zigblock++ ? 0 : (zigsig = 0))
  2007. #define zighold(z,m)    (zigsig ? 0 : (zigsig = (z), zigmask = (m), 0))
  2008. #define zigheld        (zigblock > 0)
  2009. #define zigsafe()    if (zigheld && zigsig) { \
  2010.                 if (zigblock > 0) \
  2011.                 zigblock--; \
  2012.                 if (zigblock == 0) { \
  2013.                 int zs = zigsig; \
  2014.                 zigsig = 0; \
  2015.                 fast_unblock(&zigmask); \
  2016.                 handler(zs); \
  2017.                 } \
  2018.             } else { \
  2019.                 if (zigblock > 0) \
  2020.                 zigblock--; \
  2021.             }
  2022.  
  2023. #include "ztype.h"
  2024. #include "funcs.h"
  2025.  
  2026. /* the command stack for use with %_ in prompts */
  2027.  
  2028. EXTERN unsigned char *cmdstack;
  2029. EXTERN int cmdsp;
  2030.  
  2031. #define cmdpush(X) if (!(cmdsp >= 0 && cmdsp < 256)) {;} else cmdstack[cmdsp++]=(X)
  2032. #define cmdpop() if (cmdsp <= 0) {;} else cmdsp--
  2033.  
  2034. #define CS_FOR          0
  2035. #define CS_WHILE        1
  2036. #define CS_REPEAT       2
  2037. #define CS_SELECT       3
  2038. #define CS_UNTIL        4
  2039. #define CS_IF           5
  2040. #define CS_IFTHEN       6
  2041. #define CS_ELSE         7
  2042. #define CS_ELIF         8
  2043. #define CS_MATH         9
  2044. #define CS_COND        10
  2045. #define CS_CMDOR       11
  2046. #define CS_CMDAND      12
  2047. #define CS_PIPE        13
  2048. #define CS_ERRPIPE     14
  2049. #define CS_FOREACH     15
  2050. #define CS_CASE        16
  2051. #define CS_FUNCDEF     17
  2052. #define CS_SUBSH       18
  2053. #define CS_CURSH       19
  2054. #define CS_ARRAY       20
  2055. #define CS_QUOTE       21
  2056. #define CS_DQUOTE      22
  2057. #define CS_BQUOTE      23
  2058. #define CS_CMDSUBST    24
  2059. #define CS_MATHSUBST   25
  2060. #define CS_ELIFTHEN    26
  2061. #define CS_HEREDOC     27
  2062. #define CS_HEREDOCD    28
  2063.  
  2064. #ifndef GLOBALS
  2065. extern char *cmdnames[];
  2066.  
  2067. #else
  2068. char *cmdnames[] =
  2069. {
  2070.     "for",
  2071.     "while",
  2072.     "repeat",
  2073.     "select",
  2074.     "until",
  2075.     "if",
  2076.     "then",
  2077.     "else",
  2078.     "elif",
  2079.     "math",
  2080.     "cond",
  2081.     "cmdor",
  2082.     "cmdand",
  2083.     "pipe",
  2084.     "errpipe",
  2085.     "foreach",
  2086.     "case",
  2087.     "function",
  2088.     "subsh",
  2089.     "cursh",
  2090.     "array",
  2091.     "quote",
  2092.     "dquote",
  2093.     "bquote",
  2094.     "cmdsubst",
  2095.     "mathsubst",
  2096.     "elif-then",
  2097.     "heredoc",
  2098.     "heredocd",
  2099. };
  2100.  
  2101. #endif
  2102.